package com.ruoyi.common.utils;

import com.ruoyi.common.enums.IBaseEnum;
import org.springframework.util.Assert;

import java.io.Serializable;

/**
 * @ClassName EnumUtil
 * @Description
 * @Author Small
 * @Date 2019/12/10 9:44
 * @Version 1.0
 **/
public class EnumUtil {


    /**
     * 方法描述: 根据value得到对应的枚举值
     * @Author Small
     * @param targerType
     * @param source
     * @Date 2020/3/20 10:05
     * @return T
    */
    public static <T extends IBaseEnum> T getIEnum(Class<T> targerType, Serializable source) {
        for (T enumObj : targerType.getEnumConstants()) {
            if (source.equals(enumObj.getValue())) {
                return enumObj;
            }
        }
        return null;
    }

    /**
     * 方法描述: 根据value得到对应的描述值
     * @Author Small
     * @param targerType
     * @param source
     * @Date 2020/3/20 10:08
     * @return java.lang.String
    */
    public static String getDesp(Class targerType, Serializable source){
        IBaseEnum iEnum = getIEnum(targerType, source);
        Assert.notNull(iEnum,"value不存在");
        return iEnum.getDesp();
    }





}
